class CreateGroups < ActiveRecord::Migration
  def self.up
    create_table :groups do |t|
      t.column  :name, :string, :null => false
      t.column  :owner_id, :integer, :null => false
      t.column  :teaching_id, :integer, :null => false
    end
    add_index :groups, [:teaching_id, :name], :name => 'unique_name_for_teaching', :unique => true
    add_index :groups, [:owner_id, :teaching_id], :name => 'unique_owner_for_teaching', :unique => true
    
    create_table :groups_users, :id => false do |t|
      t.column  :group_id, :integer, :null => false
      t.column  :user_id, :integer, :null => false
    end
    add_index :groups_users, [:group_id, :user_id], :unique => true
  end

  def self.down
    drop_table :groups_users
    drop_table :groups
  end
end
